<%@ page import="com.beiyou.DbUtil" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>上传文件</title>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <style>
        h3 {
            padding: 3px;
            border-bottom: 1px dashed gray;
            text-align: center;
            width: 500px;
        }

        img {
            width: 50px;
            height: 50px;
            border: 1px solid red;
            position: relative;
            left: 230px;
        }

        .page a {
            text-decoration: none;
            padding: 2px;
            margin: 2px;
            border: 1px solid gray;
        }

        .page span {
            text-decoration: none;
            padding: 2px;
            margin: 2px;
            background-color: rgba(34, 104, 232, 0.54);
            color: #fff;
            border: 1px solid gray;
        }

        li {
            text-align: center;
        }
    </style>
</head>
<body>
<%--${pageContext.request.contextPath}/--%>
<div style="font-size: x-large"><a href="upfile.jsp">上传文件</a></div>

<hr>

<%
    DbUtil du = new DbUtil();
    //du.setPageSize(3);
    long pageCount = du.getPageCount();
    int pageSize = du.getPageSize();
    // 总页数
    // 当前页
    long currPage = request.getParameter("p") == null ? 1 : Integer.parseInt(request.getParameter("p"));
    if (currPage < 1) {
        currPage = 1;
    }
    if (currPage > pageCount) {
        currPage = pageCount;
    }
    List<Map<String, Object>> list = du.query("select * from t_student order by id desc limit ?,?", (currPage - 1) * pageSize, pageSize);
    for (Map<String, Object> map : list) {
        out.print("<h3>" + map.get("name") + "</h3>");
        out.print("<img src=\"upload/" + map.get("ufile") + ".jpg\">");
    }

%>
<hr>
<br><br>
<ul class="pagination pagination-sm center-block">
    <%
        long ss = 1;
        long ee = 10;
        if (currPage > 5) {
            ss = currPage - 4;
            ee = currPage + 5;
        }

        if (currPage > 1) {
            out.print(String.format("<li class=\"page-item\"><a class=\"page-link\" href=\"?p=%d\">上一页</a></li>", currPage - 1));
        } else {
            out.print("<li class=\"page-item disabled\"><span class=\"page-link\">上一页</a></li>");
        }
        for (long i = ss; i <= ee; i++) {
            if (i > pageCount) break;
            if (i == currPage) {
                out.print(String.format("<li class=\"page-item active\"><span class=\"page-link\">%d</a></li>", i));
                continue;
            }
            out.print(String.format("<li class=\"page-item\"><a class=\"page-link\" href=\"?p=%d\">%<d</a></li>", i));
        }

        if (currPage < pageCount) {
            out.print(String.format("<li class=\"page-item\"><a class=\"page-link\" href=\"?p=%d\">下一页</a></li>", currPage + 1));
        } else {
            out.print("<li class=\"page-item disabled\"><span class=\"page-link\">下一页</a></li>");
        }
    %>
</ul>
</body>
</html>
